/**
 * Created by Administrator on 2017/12/2.
 */

$(function () {
    var k = $(window).height();
    var flag = false;
    $('.next').click(function (event) {
        $.fn.fullpage.moveSectionDown();
    });
    $('#fullpage').fullpage({
        sectionsColor:['#fadd67','#84a2d4','#ef674d','#fed','#d04759','#84d9ed','#8ac060'],
        navigation: true,
        scrollingSpeed: 1500,
        afterLoad:function (anchorLink,index) {
            if (index == 2) {
                $('.next').fadeOut();
            }
            if (index == 2 && flag == false) {
                $('.search').show().animate({'right': 370},1500,"easeOutBack",function () {
                    $('.search-01').animate({'opacity': 1},500,function () {
                        $('.search').hide();
                        $('.search-02').show().animate({'height': 30,'right': 250,'bottom':452},1000);
                        $('.big-sofa').show().animate({'height': 218},1000,"easeInOutQuart");
                        flag = true;
                        $('.word-02').animate({'opacity': 1}, 500,function () {
                            $('.next').fadeIn()
                        });
                    })
                })
            }
        },
        onLeave: function (index, nextIndex, direction) {
            $('.next').fadeOut();
            if (index == 2 && nextIndex == 3 && flag == true) {
                $('.shirt-02').show().animate({'bottom': -(k - 250),'width': 207,'left': 260},2000,function () {
                    $('.img-01').animate({'opacity': 1},500,function () {
                        $('.btn-01').animate({'opacity': 1},500,function () {
                            $('.next').fadeIn()
                        })
                    });
                });
                $('.cover').show()
            }
            if (index == 3 && nextIndex == 4) {
                $('.shirt-02').hide();
                $('.t1f').show().animate({'bottom':-(k-250+50),'left': 255},2000,function () {
                    $(this).hide();
                    $('.car-img').show();
                    $(".car").animate({"left": "150%"}, 3000,"easeInElastic",function () {
                        $('.note').show(400,function () {
                            $('.note-img').animate({'opacity': 1},1000);
                            $('.word-04').animate({'opacity': 1},1000);
                            $('.next').fadeIn()
                        })
                    });
                });
            }
            if (index == 4 && nextIndex == 5) {
                $('.hand').animate({'bottom': 0},1000,function () {
                    $('.mouse-05').animate({'opacity': 1},500,function () {
                        $('.t1f-05').show().animate({'bottom': 70},1000,function () {
                            $('.order-05').animate({'bottom': 390},500,function () {
                                $('.word-05').addClass('word-05-a');
                                $('.next').fadeIn()
                            })
                        })
                    })
                })
            }
            if (index == 5 && nextIndex == 6) {
                $('.t1f-05').animate({'bottom': -(k - 500),'left': '40%','width': 45},1000,function () {
                    $(this).hide();
                });
                $('.box').animate({'left': '38%'},1000,function () {
                    $(this).animate({"bottom": 10}, 500,function () {
                        $(this).hide();
                        $('.adress').show();
                        $('.section6').animate({'backgroundPositionX': '100%'},3000,function () {
                            $('.man').animate({'height': 305,'bottom': 116},500,function () {
                                $(this).animate({'right': '35%'},500,function () {
                                    $('.door').animate({'opacity': 1},500,function () {
                                        $('.women').show().animate({'height': 306},500);
                                        $('.get').animate({'opacity': 1},500)
                                })
                                })
                            })
                        })
                        $('.slogen').animate({'left': '30%'},3000,"easeOutBack",function () {
                            $('.next').fadeIn()
                        })
                    })
                })
            }
            if (index == 6 && nextIndex == 7) {
                setTimeout(function () {
                    $('.star').animate({'width': 120},1000,function () {
                        $('.good-07').animate({'opacity': 1}, 500,function () {
                            $('.next').fadeIn()
                        })
                    })
                },1500)
            }
            $('.begin').hover(function () {
                $('.btn-08-a').toggle()
            })
            $(document).mousemove(function (event) {
                var x = event.pageX;
                var y = event.pageY + 10;
                var minY = k - 449;
                var y = y < minY ? minY : y;
                $('.hand-08').css({'left': x,'top': y})
            })
            $('.again').click(function () {
                $.fn.fullpage.moveTo(1);
                $('img,.move').attr('style','');
                flag = false;
                $('.word-05').removeClass('word-05-a');
                $('.section6').css('backgroundPositionX', '25%')
            })
        }
    })
})